﻿using System;
using System.IO;
using System.Reflection;
using System.Web.Mvc;
using Newtonsoft.Json;

namespace NetSurveillance.WebApp.Binders
{
    public class JsonModelBinder : IModelBinder
    {
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            string jsonStr = controllerContext.HttpContext.Request[bindingContext.ModelName];
            return string.IsNullOrEmpty(jsonStr) ? null : JsonConvert.DeserializeObject(jsonStr, bindingContext.ModelType);
        }
    }
}